<template>
  <div class="contents">
    <el-dialog
        title="警告！"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
      <audio id="audioMusic" class="audio" src="music.mp3" controls autoplay="autoplay" hidden="false" ref="audio"></audio>
      <span v-html="this.AnnouncementSendModel.records[0].msgContent" class="article-content">
        消息时间：{{this.AnnouncementSendModel.records[0].sendTime}}}</span>
      <span slot="footer" class="dialog-footer">
<!--        <el-button @click="dialogVisible = false">取 消</el-button>-->
        <el-button type="primary" @click="checkDialogVisible">已 读</el-button>
      </span>
    </el-dialog>
    <div class="contetn_left">
      <div class="pagetab">
        <!-- <div class="item">实时监测</div> -->
      </div>
      <ItemWrap class="contetn_left-top contetn_lr-item" title="巡检总览">
        <LeftTop/>
      </ItemWrap>
      <ItemWrap class="contetn_left-center contetn_lr-item" title="今日巡检总览">
        <LeftCenter />
      </ItemWrap>
      <ItemWrap
        class="contetn_left-bottom contetn_lr-item"
        title="巡检数据概览"
        style="padding: 0 10px 16px 10px"
      >
        <LeftBottom />
      </ItemWrap>
    </div>
    <div class="contetn_center">
      <CenterMap class="contetn_center_top" />
    </div>
    <div class="contetn_right">
<!--      <ItemWrap-->
<!--        class="contetn_left-bottom contetn_lr-item"-->
<!--        title="报警统计"-->
<!--      >-->
<!--        <RightTop />-->
<!--      </ItemWrap>-->
      <ItemWrap class="contetn_left-top contetn_lr-item" title="气体 检测">
        <LeftTopGas/>
      </ItemWrap>

      <ItemWrap
        class="contetn_left-bottom contetn_lr-item"
        title="报警排名(TOP8)"
        style="padding: 0 10px 16px 10px"
      >
        <RightCenter />
      </ItemWrap>
      <ItemWrap
        class="contetn_left-bottom contetn_lr-item"
        title="设备报警概览 "
      >
        <RightBottom />
      </ItemWrap>
    </div>
  </div>
</template>

<script>
import LeftTop from './left-top.vue';
import LeftTopGas from './left-top-gas';
import LeftCenter from "./left-center.vue";
import LeftBottom from "./left-bottom.vue";
import CenterMap from "./center-map.vue";
import CenterBottom from "./center-bottom.vue";
import RightTop from "./right-top.vue";
import RightCenter from "./right-center.vue";
import RightBottom from "./right-bottom.vue";
import {currentGET, currentPOST} from "@/api";

export default {
  components: {
    LeftTopGas,
    LeftTop,
    LeftCenter,
    LeftBottom,
    CenterMap,
    RightTop,
    RightCenter,
    RightBottom,
    CenterBottom,
  },
  data() {
    return {
      dialogVisible: false,
      AnnouncementSendModel: {
        records: [
          {
            busId : null,
            readFlag :  null,
            anntId :  null,
            pageSize : null,
            msgAbstract : null,
            priority :  null,
            userId :  null,
            sendTime :  null ,
            openType : null,
            openPage : null,
            titile :  null ,
            msgContent : null ,
            sender :  null ,
            bizSource : null,
            pageNo : null,
            id :  null ,
            msgCategory :  null ,
            busType : null
          }
        ]
      }
    };
  },

  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      // this.$Message.warning(res.msg)
    },
    beforeDestroy() {
      this.clearData()
    },
    getData() {
      this.pageflag = true
      // this.pageflag =false
      currentGET('big11').then(res => {
        //只打印一次
        if (!this.timer) {
          console.log("报警获取", res.result);
        }
        if (res.result.total != 0  && res.result.size == 1) {
          this.AnnouncementSendModel = res.result;
          this.dialogVisible = true;
          // var mp3Url = "music.mp3";
          // var player = new Audio(mp3Url);
          // player.play(); //播放 mp3这个音频对象
          //暂停
          //player.pause();
          //player.load();
          console.log("报警获取", this.AnnouncementSendModel.records[0].msgContent);
        }
      })
    },
    ackEditByAnntIdAndUserIdByBigScreen(){
      this.dialogVisible = false;
      var a = {
        "anntId":this.AnnouncementSendModel.records[0].anntId};
      currentPOST("big12", a).then(res=>{

      })
    },
    checkDialogVisible() {
      this.ackEditByAnntIdAndUserIdByBigScreen();
    },
    clearData() {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
    },
    //轮询
    switper() {
      if (this.timer) {
        return
      }
      let looper = (a) => {
        this.getData()
      };
      this.timer = setInterval(looper, this.$store.state.setting.echartsAutoTime);
    },
  },
  filters: {
    numsFilter(msg) {
      return msg || 0;
    },
  },
  created() {
    this.getData()
  },
  mounted() {},

};
</script>
<style lang="scss" scoped>
// 内容
.contents {
  .contetn_left,
  .contetn_right {
    width: 540px;
    box-sizing: border-box;
    // padding: 16px 0;
  }

  .contetn_center {
    width: 720px;
  }

  //左右两侧 三个块
  .contetn_lr-item {
    height: 310px;
  }

  .contetn_center_top {
    width: 100%;
  }

  // 中间
  .contetn_center {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }

  .contetn_center-bottom {
    height: 315px;
  }

  //左边 右边 结构一样
  .contetn_left,
  .contetn_right {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
  }

  .article-content {
    p {
      word-wrap: break-word;
      word-break: break-all;
      text-overflow: initial;
      white-space: normal;
      font-size: .9rem !important;
      margin-bottom: .8rem;
    }
  }
}


@keyframes rotating {
    0% {
        -webkit-transform: rotate(0) scale(1);
        transform: rotate(0) scale(1);
    }
    50% {
        -webkit-transform: rotate(180deg) scale(1.1);
        transform: rotate(180deg) scale(1.1);
    }
    100% {
        -webkit-transform: rotate(360deg) scale(1);
        transform: rotate(360deg) scale(1);
    }
}
</style>
